package com.chj.design.handler;

public abstract class AbstractHandler {

    //责任链中的下一个对象
    private AbstractHandler nextHandler;

    /**
     * 责任链的下一个对象
     */
    public void setNextHandler(AbstractHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    /**
     * 具体规则子类实现
     *
     * @param filterRequest
     * @param response
     */
    abstract void doFilter(String filterRequest, String response);

    /**
     * 具体参数拦截逻辑,给子类去实现
     */
    public void filter(String request, String response) {
        doFilter(request, response);
        if (this.nextHandler != null) {
            this.nextHandler.filter(request, response);
        } else {
            System.out.println("责任链处理完成");
        }
    }
}